package com.gongJiao.controller;


import com.gongJiao.common.Result;
import com.gongJiao.entity.Info;
import com.gongJiao.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * <p>
 *  前端控制器
 * </p>
 * @author ${author}
 * @since 2021-12-25
 */
@Controller
@RequestMapping("/info")
public class InfoController {

    @Autowired
    InfoService infoService;
    /**
     * 获取网站相关信息
     * @return
     */
    @GetMapping("/getInfo")
    public String getTypeById(Model model){
        //获取信息
        Info info =infoService.getInfo();
        model.addAttribute("info",info);
        return "admin/infoEdit";
    }

    /**
     * 修改信息
     * @param info
     * @return
     */
    @PostMapping("updateInfo")
    @ResponseBody
    public Result updateType(Info info){
        info.setCreateTime(new Date());
        Boolean flag=infoService.updateInfo(info);
        if (flag) {
            return Result.success("修改成功！");
        }
        return Result.fail("修改失败！");
    }
}

